//
//  RSSession.m
//  StaffTax
//
//  Created by 侯伟 on 2020/1/2.
//  Copyright © 2020 侯伟. All rights reserved.
//

#import "RSSession.h"
#import "RSPersistentKeys.h"
#import "LocalStorage.h"
#import "NetworkConfig.h"
@implementation RSSession

/**
 登录状态
 */
+(BOOL)isLogin{
    return RSSession.token?YES:NO;
}

/// 登录名称
+(NSString*)loginName{
    NSString* loginName  = [LocalStorage.share objectForKey:keyForLoginNameKey];
    return loginName;
}

+ (void)setLoginName:(NSString *)loginName{
    if(loginName){
        [LocalStorage.share setObject:loginName forKey:keyForLoginNameKey];
    }else{
        [LocalStorage.share removeObjectForKey:keyForLoginNameKey];
    }
}

/**
 登录token
 */

+(NSString*)token{
    NSString* token = [LocalStorage.share objectForKey:keyForUserToken];
    return token;
}


+ (void)setToken:(NSString *)token{
    if(token){
        [LocalStorage.share setObject:token forKey:keyForUserToken];
    }else{
        [LocalStorage.share removeObjectForKey:keyForUserToken];
    }
}

/**
 极光推送id
*/
+ (NSString*)PushId{
    return [LocalStorage.share objectForKey:keyForJPushRegistId];
}

+ (void)setPushId:(NSString *)PushId{
    if(PushId.length){
        [LocalStorage.share setObject:PushId forKey:keyForJPushRegistId];
    }else{
        [LocalStorage.share removeObjectForKey:keyForJPushRegistId];
    }
}


/**
 移除用户缓存
 */
+ (void)clear{
    
    RSSession.token = NULL;
    
    [LocalStorage resetUser];
    
    [NetworkConfig configNetwork];
}

@end
